package com.example.doublepink.dialogautodismisstest;

import android.app.ActivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

/**
 * Created by doublepink on 16/9/21.
 */
public class SecondActivity extends AppCompatActivity{
    private long mLeftedTime;
    private TextView textView;
    private Handler mDownHandler = new Handler();

    private Runnable mDownRunnable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second_main);
        textView = (TextView)findViewById(R.id.text);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        doCountDown();

    }
    private void doCountDown() {
        mLeftedTime = 3 * 1000;
        mDownHandler.removeCallbacks(mDownRunnable);
        mDownHandler.postDelayed(mDownRunnable = new Runnable() {
            @Override
            public void run() {
                mLeftedTime -= 1000;
                if (mLeftedTime > 0) {
                    mDownHandler.postDelayed(this, 1000);
                } else {
                    mDownHandler.removeCallbacks(mDownRunnable);
                    finish();
                }
            }
        }, 1000);
    }
}
